//
//  CourseTopCell.m
//  TrainTree
//
//  Created by wanghui on 2017/9/4.
//  Copyright © 2017年 YouYeShu. All rights reserved.
//

#import "CourseTopCell.h"
#import "SDCycleScrollView.h"
@interface CourseTopCell()<SDCycleScrollViewDelegate>
/**顶部轮播图*/
@property (nonatomic, strong) SDCycleScrollView  *pageView;
/**轮播图数组*/
@property (nonatomic, strong) NSArray  *picArrs;
/**轮播图url的数组*/
@property (nonatomic, strong) NSMutableArray  *picUrlArrs;
@end

@implementation CourseTopCell

- (void)awakeFromNib {
    [super awakeFromNib];
    CGFloat height  = (ScreenWidth * 160 / 375);
    self.pageView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, ScreenWidth, height) imageURLStringsGroup:self.picUrlArrs];
    self.pageView.placeholderImage = ImageNamed(@"ty_pic");
    self.pageView.autoScrollTimeInterval = 2.0f;
    self.pageView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    self.pageView.delegate = self;
    [self addSubview:self.pageView];

}

- (NSArray *)picArrs
{
    return _picArrs?_picArrs:(_picArrs = [NSArray array]);
}

- (NSMutableArray *)picUrlArrs
{
    return _picUrlArrs?_picUrlArrs:(_picUrlArrs = [NSMutableArray array]);
}

- (void)configWithArray:(NSArray *)array 
{
    [self.picUrlArrs removeAllObjects];
    for (CarouselModel *model in array) {

        [self.picUrlArrs addObject: [NSString stringWithFormat:@"%@%@",TrainTreeFileImgURL,model.imageUrl]];
    }
    
    self.picArrs = array;
    self.pageView.imageURLStringsGroup = self.picUrlArrs;
        // 解析每个轮播图上的文字
    NSMutableArray *tmpClassName = [NSMutableArray array];
    for (int i = 0; i < array.count; i++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        CarouselModel *model = array[i];
        [dic setValue:model.lessonName forKey:@"lessonName"];
        [dic setValue:model.moduleName forKey:@"moduleName"];
        [dic setValue:model.themeName forKey:@"themeName"];
        [tmpClassName addObject:dic];

    }
    self.pageView.className = tmpClassName;
}
    ///** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    CarouselModel *model = self.picArrs[index];
    if (_delegate && [_delegate respondsToSelector:@selector(bannerToNextPageWithType:lessonId:)]) {
        [_delegate bannerToNextPageWithType: model.type lessonId:model.bannerId];
    }


}

/**当前照片*/
- (void)cycScollview:(SDCycleScrollView *)scrollview currentItemIndex:(NSInteger)index
{

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
